﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InstituteManager.Data;
using System.Data;

namespace InstituteManager.Bussiness
{
    public class ExhibitionBL
    {
        public static string errorMsg = "";
        public static List<tbl_Exhibition> getByAll()
        {
            InstituteManagerEntities InsMana = new InstituteManagerEntities();            
            List<tbl_Exhibition> exhi = InsMana.tbl_Exhibition.ToList();
            return exhi;
        }

        public static tbl_Exhibition getById(int Id)
        {
            InstituteManagerEntities InsMana = new InstituteManagerEntities();
            return InsMana.tbl_Exhibition.First(temp => temp.ExhibitionId == Id);
        }

        public static bool AddNew(tbl_Exhibition ex)
        {
            try
            {
                InstituteManagerEntities InsMana = new InstituteManagerEntities();
                InsMana.AddTotbl_Exhibition(ex);
                InsMana.SaveChanges();
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
                return false;
            }
            errorMsg = "";
            return true;
        }

        public static bool Update(tbl_Exhibition ex)
        {
            try
            {
                InstituteManagerEntities InsMana = new InstituteManagerEntities();
                tbl_Exhibition exhi =  InsMana.tbl_Exhibition.First(temp => temp.ExhibitionId == ex.ExhibitionId);
                exhi.ExhibitionName = ex.ExhibitionName;
                exhi.Place = ex.Place;
                exhi.Phone = ex.Phone;
                exhi.Email = ex.Email;
                InsMana.SaveChanges();
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
                return false;
            }
            errorMsg = "";
            return true;
        }

        public static bool Delete(int Id)
        {
            try
            {
                InstituteManagerEntities InsMana = new InstituteManagerEntities();
                InsMana.DeleteObject(InsMana.tbl_Exhibition.First(temp => temp.ExhibitionId == Id));
                InsMana.SaveChanges();
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
                return false;
            }
            errorMsg = "";
            return true;
        }

        public static List<tbl_Exhibition> SearchByName(string ExhibitionName)
        {
            InstituteManagerEntities InsMana = new InstituteManagerEntities();

            return (from sc in InsMana.tbl_Exhibition where sc.ExhibitionName.Contains(ExhibitionName) select sc).ToList<tbl_Exhibition>();
        }
    }
}
